package com.zxj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.common.pojo.R;
import com.zxj.mapper.CarConfigMapper;
import com.zxj.pojo.entity.TbBrand;
import com.zxj.pojo.entity.TbCar;
import com.zxj.pojo.entity.TbCarTypeConfigDetails;
import com.zxj.pojo.vo.ConfigVo;
import com.zxj.service.CarConfigService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-fifth
 * @description:
 * @author: 张修杰
 * @create: 2021-07-24 10:23
 **/
@Service
public class CarConfigServiceImpl implements CarConfigService {
    @Resource
    CarConfigMapper carConfigMapper;

    @Override
    public R selectAllCarConfig() {
        List<TbCarTypeConfigDetails> tbConfigs =carConfigMapper.selectList(null);
        return R.ok().put("AlltbConfigs",tbConfigs);
    }
    @Override
    public R findAllCarConfigPage(Integer currentPage, Integer pageSize, ConfigVo configVo) {

        QueryWrapper<TbCarTypeConfigDetails> wrapper=new QueryWrapper<>();

        if (StringUtils.isNotEmpty(configVo.getTypename())){
            wrapper.like("typeName",configVo.getTypename());
        }

        Page<TbCarTypeConfigDetails> page=new Page<>(currentPage,pageSize);
//        IPage<TbCar> page1=carConfigMapper.SaveCarList(page,wrapper);
        carConfigMapper.selectPage(page,wrapper);
        return R.ok().put("records",page.getRecords()).put("total",page.getTotal());

    }

    @Override
    public R updateCarConfigById(TbCarTypeConfigDetails tbCarTypeConfigDetails) {
        int i= carConfigMapper.updateById(tbCarTypeConfigDetails);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R selectCarConfigById(String id) {
        TbCarTypeConfigDetails tbCarTypeConfigDetails=carConfigMapper.selectById(id);
        return R.ok().put("tbCarTypeConfigDetails",tbCarTypeConfigDetails);
    }

    @Override
    public R insertCarConfig(TbCarTypeConfigDetails tbCarTypeConfigDetails) {
        int i= carConfigMapper.insert(tbCarTypeConfigDetails);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R deleteCarConfig(String id) {
        int i= carConfigMapper.deleteById(id);
        return (i>0)? R.ok():R.error();
    }
}
